package com.itwn.comic.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.comic.entity.Resource;
import com.itwn.comic.mapper.ResourceMapper;
import com.itwn.comic.vo.ResourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ResourceService {
    @Autowired
    ResourceMapper resourceMapper;
    public PageInfo<ResourceVo> queryResourceByPage(Integer size, Integer now, String name) {
        PageHelper.startPage(now,size);
        List<ResourceVo> list = resourceMapper.selectRoleByName(name);
        return new PageInfo<>(list);
    }

    public int addResource(Resource resource) {
        return resourceMapper.insert(resource);
    }

    public int modifyRes(Resource resource) {
        return resourceMapper.updateByPrimaryKey(resource);
    }

    @Transactional
    public void removeRes(int id) {
        resourceMapper.deleteByPrimaryKey(id);
        resourceMapper.deleteByParentId(id);
    }

    public int lockResource(Integer id, Integer status) {
        return resourceMapper.lockResources(id,status);
    }
}
